package com.gaohe.official.controller;

import java.util.List;
import java.io.IOException;

import com.gaohe.common.security.utils.SecurityUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.official.domain.FmAdvert;
import com.gaohe.official.service.IFmAdvertService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 系统广告Controller
 *
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/advert")
public class FmAdvertController extends BaseController
{
    @Autowired
    private IFmAdvertService fmAdvertService;

    /**
     * 查询系统广告列表
     */
    @RequiresPermissions("official:advert:list")
    @GetMapping("/list")
    public TableDataInfo list(FmAdvert fmAdvert)
    {
        startPage();
//        SecurityUtils.getUserId();
        List<FmAdvert> list = fmAdvertService.selectFmAdvertList(fmAdvert);
        return getDataTable(list);
    }

    /**
     * 导出系统广告列表
     */
    @RequiresPermissions("official:advert:export")
    @Log(title = "系统广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmAdvert fmAdvert)
    {
        List<FmAdvert> list = fmAdvertService.selectFmAdvertList(fmAdvert);
        ExcelUtil<FmAdvert> util = new ExcelUtil<FmAdvert>(FmAdvert.class);
        util.exportExcel(response, list, "系统广告数据");
    }

    /**
     * 获取系统广告详细信息
     */
    @RequiresPermissions("official:advert:query")
    @GetMapping(value = "/{advertId}")
    public AjaxResult getInfo(@PathVariable("advertId") Long advertId)
    {
        return success(fmAdvertService.selectFmAdvertByAdvertId(advertId));
    }

    /**
     * 新增系统广告
     */
    @RequiresPermissions("official:advert:add")
    @Log(title = "系统广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmAdvert fmAdvert)
    {
        return toAjax(fmAdvertService.insertFmAdvert(fmAdvert));
    }

    /**
     * 修改系统广告
     */
    @RequiresPermissions("official:advert:edit")
    @Log(title = "系统广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmAdvert fmAdvert)
    {
        return toAjax(fmAdvertService.updateFmAdvert(fmAdvert));
    }

    /**
     * 删除系统广告
     */
    @RequiresPermissions("official:advert:remove")
    @Log(title = "系统广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advertIds}")
    public AjaxResult remove(@PathVariable Long[] advertIds)
    {
        return toAjax(fmAdvertService.deleteFmAdvertByAdvertIds(advertIds));
    }
}
